package com.manli.common.utils;

import com.google.common.base.Splitter;

import java.util.Map;

public class StringUtil {
    public static boolean mapVlueisEmpty(Object s){
        if(s == null || s.toString().trim().equals("")){
            return false;
        }else{
            return true;
        }
    }

    public static Long mapVlueToLong(Object s){
       return Long.parseLong(s.toString());
    }

    public static boolean isEmpty(final String string) {
        return (string == null) || (string.length() == 0);
    }
    public static boolean isNotEmpty(final String string) {
        return (string != null) && (string.length() != 0);
    }
    public static boolean mapVlueisEmptyGen(Object s) {
        if(s == null || s.toString().equals("")){
            return true;
        }else{
            return false;
        }
    }

    public static String urlGetParam(String url, String name){
        String params = url.substring(url.indexOf("?") + 1, url.length());
        Map<String, String> split = Splitter.on("&").withKeyValueSeparator("=").split(params);
        if(split.get(name) != null){
            String param = split.get(name);
            if(param.indexOf("#") == -1){
                return param;
            }else{
                return param.substring(0,param.indexOf("#"));
            }
        }
        return "";

    }

    public static String deleteUrlParam(String url,String param) {
        String[] str = url.split("&");
        StringBuffer stringBuffer = new StringBuffer("");
        for(int i=0;i<str.length;i++){
            if(str[i].contains(param)){
                continue;
            }
            stringBuffer.append(str[i]);
            stringBuffer.append("&");
        }
        String noPidUrl = stringBuffer.toString();
        return noPidUrl.substring(0,noPidUrl.length() - 1);
    }


}
